#!/bin/bash

# 设置数据库连接信息
DB_USER="postgres"
DB_PASS="Pass1234"
DB_HOST="localhost"
DB_PORT="5432"

# 创建数据库
echo "Creating database ysb..."
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -c "CREATE DATABASE fsw;"
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -c "CREATE DATABASE cc_default;"
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -c "CREATE DATABASE cc_master;"
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -c "CREATE DATABASE cc_slave;"

# 导入fswatch.sql文件
echo "Importing fswatch.sql..."
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -d fsw -f fswatch.sql

psql -U $DB_USER -h $DB_HOST -p $DB_PORT -d fsw -f fs_nodes.sql
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -d fsw -f ysb_agent.sql
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -d fsw -f ysb_softphone.sql
psql -U $DB_USER -h $DB_HOST -p $DB_PORT -d fsw -f ysb_tenant.sql

echo "Database created and imported successfully."
